#include <stdio.h>



int main(void)
{
	int urn[5] = {100, 200, 300, 400, 500};
	int *ptr1, *ptr2, *ptr3;

	ptr1 = urn;
	ptr2 = &urn[2];

	printf("pointer value, dereferenced pointer, pointer address:\n");
	printf("ptr1 = %p, *ptr1 = %d, &ptr1 = %p\n", ptr1, *ptr1, &ptr1);	// 100

	// pointer addition   + 
	ptr3 = ptr1 + 4;
		printf("\t==xiaozi ==== %d\n", *ptr3);	// 500
		
	printf("\n adding an int to a pointer:\n");
	printf("ptr1 + 4 = %p, *(ptr4 + 3) = %d\n", 
				ptr1 + 4, *(ptr1 + 3));	// 400
				

	ptr1++;			// increase by degrees point    dizeng point
		printf("\t==xiaozi ==== %d\n", *ptr1);	// 200
		
	printf("\n values after ptr1++\n");
	printf("ptr1 = %p, *ptr1 = %d, &ptr1 = %p\n", 
				ptr1, *ptr1, &ptr1);	// 200

	ptr2--;			// descending		diqian point
	printf("\n values after --ptr2\n");
	printf("ptr2 = %p, *ptr2 = %d, &ptr2 = %p\n", 
				ptr2, *ptr2, &ptr2);	// 200

	--ptr1;			// huifu wei chu shi zhi
	++ptr2;			// huifu wei chu shi zhi
		printf("\t==xiaozi ==== %d\n", *ptr1);	// 100
		printf("\t==xiaozi ==== %d\n", *ptr2);	// 300
	printf("\n pointers reset to original values:\n");
	printf("ptr1 = %p, ptr2 = %p\n", 
					ptr1, ptr2);	// 300

	// yige point qianqu ling yige point
	printf("\n subtracting one pointer from another:\n");
	printf("ptr2 = %p, ptr1 = %p, ptr2 - ptr1 = %d\n", 
						ptr2, ptr1, ptr2 - ptr1); // 2


	// yige point qianqu yige zhengshu
	printf("\n subtracting an int from a pointer:\n");
	printf("ptr3 = %p, ptr3 - 2 = %p\n", 
					ptr3, ptr3 - 2);

}

